﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.BLL;
using BDCS.Model;

namespace BDCS.UI
{
    public partial class AlterBuildTypescs : Form
    {
        #region 成员字段
        private Model.T_BuildTyppes modelBuildType;
        private BDCS.BLL.T_BuildTyppes bllBuildType;
        private int btid;
        private string btName;
        private string btNameTwo;
        private string btDescribe;
        private string btDescribeTwo;
        #endregion
        #region 构造函数
        public AlterBuildTypescs()
        {
            InitializeComponent();
        }
        public AlterBuildTypescs(Model.T_BuildTyppes modelBuildType)
        {
            InitializeComponent();
            this.modelBuildType = modelBuildType;
        }
        #endregion
        #region 成员事件
        private void AlterBuildTypescs_Load(object sender, EventArgs e)
        {
            this.txtBuildTypeName.Text = this.modelBuildType.BTName;
            this.txtBuildTypeDescribe.Text = this.modelBuildType.BTypeDescribe;
            this.btid = this.modelBuildType.BTID;
            this.btName = this.modelBuildType.BTName;
            this.btDescribe = this.modelBuildType.BTypeDescribe;
            this.btNameTwo = this.modelBuildType.BTName;
            this.btDescribeTwo = this.modelBuildType.BTypeDescribe;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            modelBuildType = new Model.T_BuildTyppes();
            modelBuildType.BTID = this.btid;
            modelBuildType.BTName = this.txtBuildTypeName.Text.Trim();
            modelBuildType.BTypeDescribe = this.txtBuildTypeDescribe.Text.Trim();
            bllBuildType = new BLL.T_BuildTyppes();
            if (txtBuildTypeName.Text.Trim() != this.btName || txtBuildTypeDescribe.Text.Trim() != this.btDescribe)
            {
                try
                {
                    if (bllBuildType.Update(modelBuildType) == true)
                    {
                        this.btName = txtBuildTypeName.Text.Trim();
                        this.btDescribe = txtBuildTypeDescribe.Text.Trim();
                        BDCS.Common.TreeViewState.IsChangedAttribute = true;
                        MessageBox.Show("修改成功！");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            else
            {
                MessageBox.Show("没有修改任何内容，不需要提交！");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtBuildTypeName.Text = this.btNameTwo;
            this.txtBuildTypeDescribe.Text = this.btDescribeTwo;
            if (btName != btNameTwo || btDescribe != btDescribeTwo)
            {
                modelBuildType = new Model.T_BuildTyppes();
                modelBuildType.BTID = this.btid;
                modelBuildType.BTName = this.btNameTwo;
                modelBuildType.BTypeDescribe = this.btDescribeTwo;
                bllBuildType = new BLL.T_BuildTyppes();
                try
                {
                    bllBuildType.Update(modelBuildType);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }
        #endregion
    }
}
